package com.hzncc.scaffold.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.hzncc.scaffold.entity.Other.Paper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzncc.scaffold.entity.Vo.PaperVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 试卷表 Mapper 接口
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
public interface PaperMapper extends BaseMapper<Paper> {

//    @Select("SELECT\n" +
//            "\t`paper`.*,\n" +
//            "\t`operator`.`name` AS `operatorName`,\n" +
//            "\t`majors`.`id` AS `majorsId`,\n" +
//            "\t`majors`.`name` AS `majorsName`,\n" +
//            "\t`majors`.`pid` AS `majorsPid` \n" +
//            "FROM\n" +
//            "\t(\n" +
//            "\tSELECT\n" +
//            "\t\t`paper`.`id`,\n" +
//            "\t\t`paper`.`title`,\n" +
//            "\t\t`paper`.`createTime`,\n" +
//            "\t\t`paper`.`singleNum`,\n" +
//            "\t\t`paper`.`type`,\n" +
//            "\t\t`paper`.`multiNum`,\n" +
//            "\t\t`paper`.`judgeNum`,\n" +
//            "\t\t`paper`.`operationNum`,\n" +
//            "\t\t`paper`.`totalScore`,\n" +
//            "\t\t`paper`.`formedBy`,\n" +
//            "\t\t`paper`.`operatorId` \n" +
//            "\tFROM\n" +
//            "\t\t`paper` AS `paper` \n" +
//            "\tWHERE\n" +
//            "\t\t`paper`.`isDelete` = 0 \n" +
//            "\tORDER BY\n" +
//            "\t\t`paper`.`createTime` DESC \n" +
//            "\t\tLIMIT 0,\n" +
//            "\t\t10 \n" +
//            "\t) AS `paper`\n" +
//            "\tLEFT OUTER JOIN `user` AS `operator` ON `paper`.`operatorId` = `operator`.`id`\n" +
//            "\tLEFT OUTER JOIN ( `papermajor` AS `majors->papermajor` INNER JOIN `major` AS `majors` ON `majors`.`id` = `majors->papermajor`.`majorId` ) ON `paper`.`id` = `majors->papermajor`.`paperId` \n ${ew.customSqlSegment}" +
//            "ORDER BY\n" +
//            "\t`paper`.`createTime` DESC")
//    public List<PaperVo> listPaper(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    @Select("SELECT\n" +
            "\t`paper`.*,\n" +
            "\t`operator`.`name` AS `operatorName`\n" +
            "FROM\n" +
            "\t(\n" +
            "\tSELECT\n" +
            "\t\t`paper`.`id`,\n" +
            "\t\t`paper`.`title`,\n" +
            "\t\t`paper`.`createTime`,\n" +
            "\t\t`paper`.`singleNum`,\n" +
            "\t\t`paper`.`type`,\n" +
            "\t\t`paper`.`multiNum`,\n" +
            "\t\t`paper`.`judgeNum`,\n" +
            "\t\t`paper`.`operationNum`,\n" +
            "\t\t`paper`.`totalScore`,\n" +
            "\t\t`paper`.`formedBy`,\n" +
            "\t\t`paper`.`operatorId`,\n" +
            "\t\tpaper.isDelete \n" +
            "\tFROM\n" +
            "\t\t`paper` AS `paper` \n" +
            "\tWHERE\n" +
            "\t\t`paper`.`isDelete` = 0 \n" +
            "\tORDER BY\n" +
            "\t\t`paper`.`createTime` DESC \n" +
            "\t) AS `paper`\n" +
            "\tLEFT OUTER JOIN `user` AS `operator` ON `paper`.`operatorId` = `operator`.`id`\n" +
            "\tLEFT OUTER JOIN ( `papermajor` AS `majors->papermajor` INNER JOIN `major` AS `majors` ON `majors`.`id` = `majors->papermajor`.`majorId` ) ON `paper`.`id` = `majors->papermajor`.`paperId`\n ${ew.customSqlSegment}" +
            "ORDER BY\n" +
            "\t`paper`.`createTime` DESC")
    public List<PaperVo> listPaperPlus(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);


    @Select("SELECT\n" +
            "\tCOUNT( DISTINCT id ) \n" +
            "FROM\n" +
            "\t(\n" +
            "\tSELECT\n" +
            "\t\t`paper`.*\n" +
            "\tFROM\n" +
            "\t\t(\n" +
            "\t\tSELECT\n" +
            "\t\t\t`paper`.`id`,\n" +
            "\t\t\t`paper`.`title`,\n" +
            "\t\t\t`paper`.`createTime`,\n" +
            "\t\t\t`paper`.`singleNum`,\n" +
            "\t\t\t`paper`.`type`,\n" +
            "\t\t\t`paper`.`multiNum`,\n" +
            "\t\t\t`paper`.`judgeNum`,\n" +
            "\t\t\t`paper`.`operationNum`,\n" +
            "\t\t\t`paper`.`totalScore`,\n" +
            "\t\t\t`paper`.`formedBy`,\n" +
            "\t\t\t`paper`.`operatorId`,\n" +
            "\t\t\tpaper.isDelete \n" +
            "\t\tFROM\n" +
            "\t\t\t`paper` AS `paper` \n" +
            "\t\tWHERE\n" +
            "\t\t\t`paper`.`isDelete` = 0 \n" +
            "\t\tORDER BY\n" +
            "\t\t\t`paper`.`createTime` DESC \n" +
            "\t\t) AS `paper`\n" +
            "\t\tLEFT OUTER JOIN ( `papermajor` AS `majors->papermajor` INNER JOIN `major` AS `majors` ON `majors`.`id` = `majors->papermajor`.`majorId` ) ON `paper`.`id` = `majors->papermajor`.`paperId` \n ${ew.customSqlSegment}" +
            "\tORDER BY\n" +
            "\t`paper`.`createTime` DESC \n" +
            "\t) AS `total`")
    public Integer selectTotal(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);


    @Select("SELECT\n" +
            "\t`paper`.`id`,\n" +
            "\t`paper`.`formedBy`,\n" +
            "\t`paper`.`title`,\n" +
            "\t`paper`.`examTime`,\n" +
            "\t`paper`.`theoryQuestion`,\n" +
            "\t`paper`.`operationQuestion`,\n" +
            "\t`paper`.`totalScore`,\n" +
            "\t`paper`.`passScore`,\n" +
            "\t`paper`.`perSingle`,\n" +
            "\t`paper`.`perMulti`,\n" +
            "\t`paper`.`perJudge`,\n" +
            "\t`paper`.`perOperation`,\n" +
            "\t`paper`.`singleNum`,\n" +
            "\t`paper`.`multiNum`,\n" +
            "\t`paper`.`judgeNum`,\n" +
            "\t`paper`.`operationNum`,\n" +
            "\t`paper`.`createTime`,\n" +
            "\t`majors`.`id` AS `majorsId`,\n" +
            "\t`majors`.`name` AS `majorsName`,\n" +
            "\t`majors`.`pid` AS `majorsPid` \n" +
            "FROM\n" +
            "\t`paper` AS `paper`\n" +
            "\tLEFT OUTER JOIN ( `papermajor` AS `majors->papermajor` INNER JOIN `major` AS `majors` ON `majors`.`id` = `majors->papermajor`.`majorId` ) ON `paper`.`id` = `majors->papermajor`.`paperId` ${ew.customSqlSegment}")
    public Paper detail(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);


    @Select("SELECT task.paperId FROM `task`")
    public List<Integer> taskPaperIdList();
}
